package com.didispace.web;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

@RestController
public class ConsumerController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    private List<RestTemplate> list;

    @Autowired
    private Map<String,RestTemplate> map;

    @Autowired
    private Environment env;

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    //@HystrixCommand(fallbackMethod = "addServiceFallback")
    public String add() {
        System.out.println("----");
        return restTemplate.getForEntity("http://COMPUTE-SERVICE/compute/add?a=10&b=20", String.class).getBody();
    }


/*    public String addService() {
        return restTemplate.getForEntity("http://COMPUTE-SERVICE/add?a=10&b=20", String.class).getBody();
    }*/

    public String addServiceFallback() {
        return "error";
    }
}